package com.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.clms.common.R;
import com.manage.mapper.CouponHistoryMapper;
import com.manage.pojo.entity.CouponHistory;
import com.manage.pojo.entity.TbClient;
import com.manage.pojo.entity.TbCoupon;
import com.manage.pojo.vo.CouponHistoryVo;
import com.manage.service.CouponHistoryService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Wrapper;

/**
 * @program: clms-third
 * @description: 优惠券记录的业务层
 * @author: 林子洁
 * @create: 2021-07-23 20:58
 **/
@Service
public class CouponHistoryImpl implements CouponHistoryService {
    @Resource
    private CouponHistoryMapper historyMapper;

    @Override
    public R initcouponHistory(Integer currentPage, Integer pageSize, CouponHistoryVo couponHistoryVo) {
        Page<CouponHistory> couponHistoryPage=new Page<>(currentPage,pageSize);
        QueryWrapper<TbClient> historyQuery=new QueryWrapper<>();
        if(StringUtils.isNotEmpty(couponHistoryVo.getClientName())){
            historyQuery.like("clientName",couponHistoryVo.getClientName());
        }
        QueryWrapper<TbCoupon> couWrapp=new QueryWrapper<>();
        if(StringUtils.isNotEmpty(couponHistoryVo.getName())){
            historyQuery.like("couponName",couponHistoryVo.getName());
        }
        IPage<CouponHistory> couponHistoryIPage = historyMapper.initCouponHistory(couponHistoryPage, historyQuery,couWrapp);

        return R.ok().put("records",couponHistoryIPage.getRecords()).put("total",couponHistoryIPage.getTotal());
    }

    @Override
    public R deleteCouponHistory(Integer id) {
        historyMapper.deleteById(id);
        return R.ok().message("好了");
    }
}
